﻿// COPYRIGHT (C) Markeluo ALL RIGHTS RESERVED. 
// GITEE: https://gitee.com/luowanli/AntdUI 
// QQ: 563944808

using System.ComponentModel;

namespace IMES.Page
{
    public partial class BaseMenuBar : UserControl
    {
        public delegate void MenuBarClickEventArg(BaseMenuBarButtonType type, object sender, EventArgs args);

        [Description("菜单兰按钮点击事件"), Category("按钮事件")]
        public event MenuBarClickEventArg MenuBarClickEvent;
        public BaseMenuBar()
        {
            InitializeComponent();
        }

        #region 属性
        bool isShowAdd = true;
        [Description("是否显示新增按钮"), Category("显示控制"), DefaultValue(true)]
        public bool IsShowAdd
        {
            get { return isShowAdd; }
            set
            {
                isShowAdd = value;
                btnAdd.Visible = isShowAdd;
            }
        }

        bool isShowEdit = true;
        [Description("是否显示编辑按钮"), Category("显示控制"), DefaultValue(true)]
        public bool IsShowEdit
        {
            get { return isShowEdit; }
            set
            {
                isShowEdit = value;
                btnEdit.Visible = isShowEdit;
            }
        }

        bool isShowDel = true;
        [Description("是否显示删除按钮"), Category("显示控制"), DefaultValue(true)]
        public bool IsShowDel
        {
            get { return isShowDel; }
            set
            {
                isShowDel = value;
                btnDel.Visible = isShowDel;
            }
        }

        bool isShowExport = true;
        [Description("是否显示导出按钮"), Category("显示控制"), DefaultValue(true)]
        public bool IsShowExport
        {
            get { return isShowExport; }
            set
            {
                isShowExport = value;
                btnExport.Visible = isShowExport;

                if (!isShowPrint && !isShowExport)
                {
                    divider_Split.Visible = false;
                }
                else
                {
                    divider_Split.Visible = true;
                }
            }
        }

        bool isShowPrint = true;
        [Description("是否显示打印按钮"), Category("显示控制"), DefaultValue(true)]
        public bool IsShowPrint
        {
            get { return isShowPrint; }
            set
            {
                isShowPrint = value;
                btnPrint.Visible = isShowPrint;

                if (!isShowPrint && !isShowExport)
                {
                    divider_Split.Visible = false;
                }
                else
                {
                    divider_Split.Visible = true;
                }
            }
        }
        #endregion

        #region 按钮事件处理
        private void btnAdd_Click(object sender, EventArgs e)
        {
            TriggerEvent(BaseMenuBarButtonType.Add, sender, e);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            TriggerEvent(BaseMenuBarButtonType.Edit, sender, e);
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            TriggerEvent(BaseMenuBarButtonType.Del, sender, e);
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            TriggerEvent(BaseMenuBarButtonType.Export, sender, e);
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            TriggerEvent(BaseMenuBarButtonType.Print, sender, e);
        }
        private void TriggerEvent(BaseMenuBarButtonType btnType,object sender, EventArgs e) {
            if (MenuBarClickEvent != null) {
                MenuBarClickEvent(btnType,sender,e);
            }
        }
        #endregion
    }

    /// <summary>
    /// MenuBar按钮类型
    /// </summary>
    public enum BaseMenuBarButtonType
    {
        /// <summary>
        /// 新增按钮
        /// </summary>
        Add,
        /// <summary>
        /// 编辑按钮
        /// </summary>
        Edit,
        /// <summary>
        /// 删除按钮
        /// </summary>
        Del,
        /// <summary>
        /// 导出按钮
        /// </summary>
        Export,
        /// <summary>
        /// 打印按钮
        /// </summary>
        Print,
    }
}
